package com.scorekeeper;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.content.Context;

import com.scorekeeper.objects.Division;
import com.scorekeeper.objects.Extension;
import com.scorekeeper.objects.Extension.CastType;
import com.scorekeeper.objects.Game;
import com.scorekeeper.objects.Season;
import com.scorekeeper.objects.Team;
import com.scorekeeper.utils.DBProvider;
import com.scorekeeper.utils.DBProvider.Table;
import com.scorekeeper.utils.Loader;
import com.scorekeeper.utils.Logger;

@SuppressWarnings("unused")
public class Test {
	DBProvider db = null;
	
	public void CreateTestDB() {
		DBProvider db = new DBProvider();
		db.open();
		
		insertTest();
		loadTest();
		updateTest();
		
		db.close();
	}
	
	private void insertTest() {
		int homeTeamID;
		int awayTeamID;
		
		Season season = new Season();
		season.name = "20112012";
		season.save();
		
		Division division = new Division();
		division.name = "Northwest";
		division.save();
		
		Team team = new Team();
		team.name = "Calgary Flames";
		team.acro = "CAL";
		team.gamesPlayed = 20;
		team.wins = 15;
		team.losses = 5;
		team.points = 30;
		team.divisionId = division._id;
		team.save();
		homeTeamID = team._id;
		
		team = new Team();
		team.name = "Edmonton Oilers";
		team.acro = "EDM";
		team.gamesPlayed = 20;
		team.wins = 12;
		team.losses = 8;
		team.points = 24;
		team.divisionId = division._id;
		team.save();
		awayTeamID = team._id;
		
		Game game = new Game();
		try {
			DateFormat df = new SimpleDateFormat("mm/dd/yyyy");
			game.gameDate = df.parse("12/12/2011");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			Logger.LogError(e);
		} //TODO: Errors
		game.awayTeamId = awayTeamID;
		game.homeTeamId = homeTeamID;
		game.homeScore = 4;
		game.awayScore = 1;
		game.save();
		
		Extension ext = new Extension();
		ext.name = "OTL";
		ext.value = "2";
		ext.setExtType(CastType.INT.toInt());
		ext.teamId = 2;
		ext.save();
	}
	
	private void loadTest() {
		Loader loader = new Loader();
		
		Season season = loader.loadSeason(1);
		Division division = loader.loadDivision(1);
		Team team = loader.loadTeam(1);
		Game game = loader.loadGame(1);
		Extension ext = loader.loadExtension(1);
	}
	
	private void updateTest() {
		Loader loader = new Loader();
		
		Season season = loader.loadSeason(1);
		season.name = "20102011";
		season.save();
		
		Division division = loader.loadDivision(1);
		division.name = "Pacific";
		division.save();
		
		Team team = loader.loadTeam(2);
		team.name = "San Jose Sharks";
		team.acro = "SJS";
		team.save();
		
		Game game = loader.loadGame(1);
		game.homeScore = 3;
		game.awayScore = 2;
		game.save();
		
		Extension ext = loader.loadExtension(1);
		ext.value = "1";
		ext.save();
		
	}
}